#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

//function object
template <typename K, typename T>
class value_equals {
  T value;
public:
  value_equals(T t):value(t){} //or const T& t but not T& t
  bool operator()(pair<const K, T> elem){ return elem.second == value;}
  //can not be pair<const K, T>& elem
};

int main()
{
  typedef map<float,float> FloatFloatMap;
  FloatFloatMap ffmap;
  FloatFloatMap::iterator iter;

  //fill associative container
  for(int i = 0;i<7;i++){
    ffmap[i+1] = 7-i;
  }

  //search element with key 3.0
  //logarithmic complexity O(log(n))
  iter = ffmap.find(3.0);
  if(iter!=ffmap.end()){
    cout<<iter->first<<": "<<iter->second<<endl;
  }

  //search element with value 3.0
  //linear complexity O(n)
  iter = find_if(ffmap.begin(),ffmap.end(),value_equals<float,float>(3.0));
  if(iter!=ffmap.end()){
    cout<<iter->first<<": "<<iter->second<<endl;
  }

  return 0;
}

